// 完成对wx.request的二次封装和接口封装
module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};
/******/
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/
/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId]) {
/******/ 			return installedModules[moduleId].exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			i: moduleId,
/******/ 			l: false,
/******/ 			exports: {}
/******/ 		};
/******/
/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ 		// Flag the module as loaded
/******/ 		module.l = true;
/******/
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/
/******/
/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;
/******/
/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;
/******/
/******/ 	// define getter function for harmony exports
/******/ 	__webpack_require__.d = function(exports, name, getter) {
/******/ 		if(!__webpack_require__.o(exports, name)) {
/******/ 			Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ 		}
/******/ 	};
/******/
/******/ 	// define __esModule on exports
/******/ 	__webpack_require__.r = function(exports) {
/******/ 		if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ 			Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ 		}
/******/ 		Object.defineProperty(exports, '__esModule', { value: true });
/******/ 	};
/******/
/******/ 	// create a fake namespace object
/******/ 	// mode & 1: value is a module id, require it
/******/ 	// mode & 2: merge all properties of value into the ns
/******/ 	// mode & 4: return value when already ns object
/******/ 	// mode & 8|1: behave like require
/******/ 	__webpack_require__.t = function(value, mode) {
/******/ 		if(mode & 1) value = __webpack_require__(value);
/******/ 		if(mode & 8) return value;
/******/ 		if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ 		var ns = Object.create(null);
/******/ 		__webpack_require__.r(ns);
/******/ 		Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ 		if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ 		return ns;
/******/ 	};
/******/
/******/ 	// getDefaultExport function for compatibility with non-harmony modules
/******/ 	__webpack_require__.n = function(module) {
/******/ 		var getter = module && module.__esModule ?
/******/ 			function getDefault() { return module['default']; } :
/******/ 			function getModuleExports() { return module; };
/******/ 		__webpack_require__.d(getter, 'a', getter);
/******/ 		return getter;
/******/ 	};
/******/
/******/ 	// Object.prototype.hasOwnProperty.call
/******/ 	__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "";
/******/
/******/
/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(__webpack_require__.s = 0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {

"use strict";



/* eslint-disable */
// 小程序开发api接口工具包，https://github.com/gooking/wxapi
var API_BASE_URL = '';
// https://api.it120.cc/tz/shop/goods/detail
// var API_BASE_URL = 'http://127.0.0.1:8081';
var subDomain = '-';

var request = function request(url, needSubDomain, method, data) {
  // https://api.it120.cc/ljf/banner/list
  var _url = API_BASE_URL + (needSubDomain ? '/' + subDomain : '') + url;


  return new Promise(function (resolve, reject) {
    wx.request({
      url: _url,
      method: method,
      data: data,
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      success: function success(request) {
        resolve(request.data);
      },
      fail: function fail(error) {
        reject(error);
      },
      complete: function complete(aaa) {
        // 加载完成
      }
    });
  });
};

/**
 * 小程序的promise没有finally方法，自己扩展下
 */
Promise.prototype.finally = function (callback) {
  var Promise = this.constructor;
  return this.then(function (value) {
    Promise.resolve(callback()).then(function () {
      return value;
    });
  }, function (reason) {
    Promise.resolve(callback()).then(function () {
      throw reason;
    });
  });
};

module.exports = {
  init2: function init2(a, b) {  //导出初始路径和域名的方法
    API_BASE_URL = a;
    subDomain = b;
  },
  init: function init(b) { //导出初始化方法 传入副域名
    subDomain = b;
  },
  request: request,  //导出请求方法
  // 请求分类的方法
  getCategoryApi(){
      //                 接口地址                是否需要副域名  
      return request("/shop/goods/category/all",true,'get')
  },
  // 请求分类商品数据
  getCategoryProduct(data){
    return request("/shop/goods/list",true,"post",data)
  },
  getGoodsInfo(id){ // 获取商品详情的接口
    return request("/shop/goods/detail",true,"get",{id:id})
  },
  login_wx(code){ //获取公司的登录数据
    return request('/user/wxapp/login', true, 'post', {
      code: code,
      type: 2
    });
  },
  register_complex(data){ //注册接口
    return request("/user/wxapp/register/complex",true,"post",data)
  },
  userDetail(token){ //获取用户信息接口
    return request("/user/detail",true,"get",{
      token:token
    })
  },
  shippingCarInfoAddItem(token,goodsId,number,sku){ //加入购物车的接口
    return request("/shopping-cart/add",true,"post",{
      token:token,
      goodsId:goodsId,
      number:number,
      sku:JSON.stringify(sku)
    })
  },
  shippingCarInfo(token){ //获取购物车数据接口
    return request("/shopping-cart/info",true,"get",{
      token:token
    })
  },
  delCart(token,key){//删除购物车
      return request("/shopping-cart/remove",true,"post",{
        token:token,
        key:key
      })
  },
  getDefaultAddress(token){ //获取默认地址接口
      return request("/user/shipping-address/default/v2",true,"get",{
        token:token
      })
  },
  getAddressList(token){ //获取地址列表
    return request("/user/shipping-address/list",true,"get",{
      token:token
    })
  },
  selectAddress(data){ //选择地址
    return request("/user/shipping-address/update",true,"post",data)
  },
  addAddress(data){
    return request("/user/shipping-address/add",true,"post",data)
  },
  getProvince(){ //获取省的接口
      return request("/common/region/v2/province",false,"get")
  },
  getCityAndArea(pid){
    return request("/common/region/v2/child",false,"get",{
      pid:pid
    })
  },
  getEditAddress(id,token){ //获取编辑的地址
    return request("/user/shipping-address/detail/v2",true,"get",{
      id:id,
      token:token
    })
  },
  delAddress(token,id){  //删除地址接口
    return request('/user/shipping-address/delete',true,"post",{
      token:token,
      id:id
    })
  },
  orderCreateApi(data){ //创建订单
      return request("/order/create",true,"post",data)
  },
  getBadge(token){ //获取徽章的接口
    return request("/order/statistics",true,"get",{
      token:token
    })
  },
  getMyorder(token,status){ //获取订单列表接口
    return request("/order/list",true,"post",{
      token:token,
      status:status
    })
  },
  closeOrder(orderId,token){ //关闭订单
    return request("/order/close",true,"post",{
      orderId:orderId,
      token:token
    })
  },
  ymdLogin(data){
    return request("https://api.ymduo.com/Member/MobLogin",false,"post",data)
  }
};
/***/ })
/******/ ]);
